I tried a Gates Script but the script works fine but the 2nd Remote Event doesnt like to fire. It does nothing.
--This Works Fine
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("HalloweenGatesTakeMoney")
local Price = script.Parent:WaitForChild("Price").Value
script.Parent.MouseButton1Click:Connect(function(player)
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.Shadow.Visible = false
local GateName = script.Parent:WaitForChild("Gate").Value
GateName:Destroy()
remoteEvent:FireServer(Price)
end)
--But this does nothing
remoteEvent2.OnServerEvent:Connect(function(player, Price)
player.EventMoney.Sweets.Value = player.EventMoney.Sweets.Value - Price
wait(1)
if player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "HauntedEntrance" then
player:WaitForChild("HalloweenGates").HauntedEntrance.Value = true
elseif player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "PumpkinCave" then
player:WaitForChild("HalloweenGates").PumpkinCave.Value = true
elseif player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "HauntedBiome" then
player:WaitForChild("HalloweenGates").HauntedBiome.Value = true
elseif player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "GiantPumpkin" then
player:WaitForChild("HalloweenGates").GiantPumpkin.Value = true
end
end)
--Full script of above
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("HalloweenGates")
local remoteEvent2 = ReplicatedStorage:WaitForChild("HalloweenGatesTakeMoney")
remoteEvent.OnServerEvent:Connect(function(player, Price, GateName, GateValue)
if player.EventMoney.Sweets.Value >= Price then
player.PlayerGui.HalloweenGates.Frame.Visible = true
player.PlayerGui.HalloweenGates.Shadow.Visible = true
player.PlayerGui.HalloweenGates.Frame.Price.Text = "This Gate costs "..Price.." Sweets"
player.PlayerGui.HalloweenGates.Frame.Buy.Gate.Value = GateName
player.PlayerGui.HalloweenGates.Frame.Buy.Price.Value = Price
player.PlayerGui.HalloweenGates.Frame.Buy.GateValueName.Value = GateValue
end
end)
remoteEvent2.OnServerEvent:Connect(function(player, Price)
player.EventMoney.Sweets.Value = player.EventMoney.Sweets.Value - Price
wait(1)
if player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "HauntedEntrance" then
player:WaitForChild("HalloweenGates").HauntedEntrance.Value = true
elseif player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "PumpkinCave" then
player:WaitForChild("HalloweenGates").PumpkinCave.Value = true
elseif player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "HauntedBiome" then
player:WaitForChild("HalloweenGates").HauntedBiome.Value = true
elseif player.PlayerGui:WaitForChild("HalloweenGates").Frame.Buy.GateValueName == "GiantPumpkin" then
player:WaitForChild("HalloweenGates").GiantPumpkin.Value = true
end
end)
--Here's where I fire the remoteEvent2 event
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("HalloweenGatesTakeMoney")
local Price = script.Parent:WaitForChild("Price").Value
script.Parent.MouseButton1Click:Connect(function(player)
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.Shadow.Visible = false
local GateName = script.Parent:WaitForChild("Gate").Value
GateName:Destroy()
remoteEvent:FireServer(Price)
end)
Related
I would explain better here, I'm doing a role game and I do ranks enter image description here
But if somebody another joins then the text over the head will Destroy and to another player spawn the GUI.
The script:
local ServerStorage = game:GetService("ServerStorage")
local Tag = ServerStorage.Tag
local CloneTag = Tag:Clone()
local NameTag = CloneTag.NameTag
local RankTag = CloneTag.RankTag
local VIPTag = CloneTag.VIPTag
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
CloneTag.Parent = char.Head
if player:IsInGroup(14472135) then
if player:GetRankInGroup(14472135) == 1 then
NameTag.Text = player.Name
RankTag.Text = "Trainee"
elseif player:GetRankInGroup(14472135) == 2 then
NameTag.Text = player.Name
RankTag.Text = "Police"
elseif player:GetRankInGroup(14472135) == 3 then
NameTag.Text = player.Name
RankTag.Text = "Specialist"
elseif player:GetRankInGroup(14472135) == 4 then
NameTag.Text = player.Name
RankTag.Text = "Sergeant"
elseif player:GetRankInGroup(14472135) == 252 then
NameTag.Text = player.Name
RankTag.Text = "Corporal"
elseif player:GetRankInGroup(14472135) == 253 then
NameTag.Text = player.Name
RankTag.Text = "Major"
elseif player:GetRankInGroup(14472135) == 254 then
NameTag.Text = player.Name
RankTag.Text = "Lieutenant"
VIPTag.Visible = true
elseif player:GetRankInGroup(14472135) == 255 then
NameTag.Text = player.Name
RankTag.Text = "Colonel"
VIPTag.Visible = true
end
else
NameTag.Text = player.Name
RankTag.Text = "Immigrant"
end
end)
end)
Any Suggestion?
Thanks
As I said in my comment, you simply move the variables so that the cloning is done when a character spawns. There are also ways to make this code better. (1) You can use a table to specify each rank's text, which will shorten it. You can use another table (or the same table with more detailed table values) to store the visibility of the VIP tag. (2) You also don't need to do NameTag.Text = player.Name in every if-elseif body, you can move it out of the if so that it will always happen.
I can show a quick example of fix #1:
local ranks = {
[1] = "Trainee",
[2] = "Police",
[3] = "Specialist",
--...
[255] = "Colonel"
}
local rankVIP = {
[254] = true,
[255] = true
}
and then, all you need to set someone's rank label's text is this:
local rankInGroup = player:GetRankInGroup(14472135)
RankTag.Text = ranks[rankInGroup]
VIPTag.Visible = rankVIP[rankInGroup] or false
Here, the or false means "if I couldn't find this (if this is nothing, if this is nil), make the visibility false. If I did find something, then it will be that."
With all of the fixes and improvements, here is the new code:
local ServerStorage = game:GetService("ServerStorage")
local Tag = ServerStorage.Tag
local ranks = {
[1] = "Trainee",
[2] = "Police",
[3] = "Specialist",
[4] = "Sergeant",
[252] = "Corporal",
[253] = "Major",
[254] = "Lieutenant",
[255] = "Colonel"
}
local rankVIP = {
[254] = true,
[255] = true
}
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local CloneTag = Tag:Clone()
local NameTag = CloneTag.NameTag
local RankTag = CloneTag.RankTag
local VIPTag = CloneTag.VIPTag
NameTag.Text = player.Name
CloneTag.Parent = char.Head
if player:IsInGroup(14472135) then
local rankInGroup = player:GetRankInGroup(14472135)
RankTag.Text = ranks[rankInGroup]
VIPTag.Visible = rankVIP[rankInGroup] or false
else
RankTag.Text = "Immigrant"
end
end)
end)
Good day,
i have the problem that i wana make my visit ui only visible when i am at spawn so at first i wanted to do it with checking the team but i dont found any solousion on how to check which player is in which and than disable/enable ui for them. So after this i made an bool inside of the ui named Loby and got it to work that it turns on / off based on where you are but the problem is that i dont get the ui working i tried this now for serveral hours but i just dont get it and i dont know why. Its only prints not in Loby else if im in Loby or in a round ;(, i hope someone can help me!, Good day
FyMa2618
local loby = script.Parent.Loby
while loby.Value == false do
print("Not In Lobby")
script.Parent.Enabled = false
wait(.1)
end
while loby.Value == true do
local ready = script.Parent.Loaded
print("Lobby is Active")
script.Parent.Enabled = true
wait(.1)
end
--its a local script in the same position as the Bool.
The round script(nedded for the bool)
local intermission = 25
local roundLength = 45
local inRound = game.ReplicatedStorage.InRound
local staus = game.ReplicatedStorage.Status
-- when round value is changed
inRound.Changed:Connect(function()
if inRound.Value == false then
for i, plr in pairs(game.Players:GetChildren()) do
local char = plr.Character
local humanRoot = char:WaitForChild("HumanoidRootPart")
humanRoot.CFrame = game.Workspace.lobbySpawn.CFrame
end
end
end)
-- changes the status
local function round()
while true do
inRound.Value = false
for i = intermission, 0, -1 do
staus.Value = "Game will start in "..i.." seconds"
wait(1)
end
inRound.Value = true
wait(3)
for i = roundLength, 0, -1 do
wait(1)
staus.Value = "Game will end in "..i.." seconds"
local playing = {}
for i, plr in pairs(game.Players:GetChildren()) do
if plr.Team.Name == "Playing" then
local b = game.StarterGui.SpectateGUI.Loby
b.Value = false
table.insert(playing, plr.Name)
print("inserted player")
end
end
if #playing == 0 then
staus.Value = "Everyone Has Died"
wait(3)
break
end
end
end
end
The Region 3 Code(also needed for the bool)
local RegionPart = game.Workspace.RegionPart
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)
local region = Region3.new(pos1, pos2)
--[[
local part = Instance.new("Part")
part.Anchored = true
part.Size = region.Size
part.Parent = game.Workspace
part.CanCollide = false
part.Transparency = 0.4
dont worry about this
]]--
while true do
wait()
local partsInRegion = workspace:FindPartsInRegion3(region, nil, 1000)
for i, part in pairs(partsInRegion) do
if part.Parent:FindFirstChild("Humanoid") ~= nil then
local char = part.Parent
local loby = game.StarterGui.SpectateGUI.Loby
loby.Value = true
end
end
end[Starter UI][1]
I'm making a transformation script and I'm trying to get the LocalPlayer but this error appears:
13:54:03.806 ServerScriptService.SSJScript:2: attempt to index nil with 'GetMouse' - Server - SSJScript:2
How to fix?
This is my code:
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local chr = plr.Character
local offence = {
"AAARGH!! I HATE YOU!!",
"FUS RO DAH!",
"I'M COMING FOR THE SAAUCE!",
"IT IS TIME TO PERISH!",
"POOTIS POOTIS POOTIS POOTIS!"
}
local transformcooldown = 10
local healthboost = 1000
local speedboost = 32
local aura = game.ReplicatedStorage.Aura
local hair = game.ReplicatedStorage.Hair
local anim = chr.Humanoid:LoadAnimation(game.ReplicatedStorage.Animation)
local iscooldown = false
local ison = plr.SSJOnOff.Value
local cooldown = 10
game.Players.PlayerAdded:Connect(function(plrjoin)
plr = plrjoin
end)
mouse.KeyDown:connect(function(key)
if iscooldown == false then
key = string.lower(key)
if string.byte(key) == 48 then
local indicator = plr.SSJOnOff
if indicator.Value == false then
chr.Humanoid.WalkSpeed = 0
ison = true
game:GetService("Chat"):Chat(plr.Head,offence[math.random(1,#offence)])
wait(1)
anim:Play()
wait(1.4)
aura:Clone().Parent = chr.HumanoidRootPart
hair:Clone().Parent = chr
wait(0.6)
chr.Humanoid.MaxHealth = healthboost
chr.Humanoid.Health = healthboost / 2
chr.Humanoid.WalkSpeed = chr.Humanoid.WalkSpeed + speedboost
else
ison = false
iscooldown = true
chr.Hair:destroy()
chr.HumanoidRootPart.Aura:destroy()
chr.Humanoid.WalkSpeed = chr.Humanoid.WalkSpeed - speedboost
chr.Humanoid.Health = 100
chr.Humanoid.MaxHealth = 100
wait(cooldown)
end
end
end
The code need to be in a LocalScript part.
The function GetMouse() is on the screen on the Player so the Server cant know where is your mouse.
PS: game.Players.LocalPlayer is nil because it's a ServerScript and not a LocalScript
Write this code in a localscript and NOT in ServerScriptService
local player = game.Players.LocalPlayer
I'm trying to do something like a spear throw and I'm so confused. It says:
ServerScriptService.FireMagic.FireSpear:16: attempt to index nil with 'Position'
Anyways, here's the LocalScript code:
wait(1)
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Mouse = Player:GetMouse()
local rp = game:GetService("ReplicatedStorage")
local FireSpear = rp:WaitForChild("FireRemote")
local UIS = game:GetService("UserInputService")
local debounce = true
local cd = 10
UIS.InputBegan:Connect(function(input, isTyping)
if isTyping then
return
elseif input.KeyCode == Enum.KeyCode.E and debounce and Character then
debounce = false
FireSpear:FireServer()
wait(cd)
debounce = true
end
end)
and the Script:
wait(1)
local rp = game:GetService("ReplicatedStorage")
local ss = game:GetService("ServerStorage")
local Debris = game:GetService("Debris")
local ssFireSpear = ss.FireMagic:WaitForChild("ssFireSpear")
local FireRemote = rp:WaitForChild("FireRemote")
local UhTable = {}
local function LookatMouse(Mouse, RootPart)
local bodyG = Instance.new("BodyGyro")
bodyG.MaxTorque = Vector3.new(0, 500000, 0)
bodyG.P = 10000
bodyG.CFrame = CFrame.new(RootPart.Position, Mouse.Position)
bodyG.Parent = RootPart
Debris:AddItem(bodyG, 1)
end
local function MoveTowardsMouse(Mouse, Main)
local bodyV = Instance.new("BodyVelocity")
bodyV.MaxForce = Vector3.new(500000, 500000, 500000)
bodyV.Velocity = CFrame.new(Main.Position, Mouse.Position).LookVector * 100
bodyV.Parent = Main
local bodyG = Instance.new("BodyGyro")
bodyG.MaxTorque = Vector3.new(500000, 500000, 500000)
bodyG.P = 10000
bodyG.CFrame = CFrame.new(Main.Position, Mouse.Position)
bodyG.Parent = Main
end
FireRemote.OnServerEvent:Connect(function(Player, Mouse_CFrame)
if UhTable[Player.Name] == true then
return
end
UhTable[Player.Name] = true
local Character = Player.Character
local RootPart = Character:WaitForChild("HumanoidRootPart")
local folder = workspace:FindFirstChild("DebrisFolder") or Instance.new("Folder",workspace)
folder.Name = "DebrisFolder"
local RightHand = Character:WaitForChild("RightHand")
local FireSpear = ssFireSpear:Clone()
local Handle = FireSpear:WaitForChild("Handle")
local Hitbox = FireSpear:WaitForChild("Hitbox")
local Mesh = FireSpear:WaitForChild("Mesh")
FireSpear:SetPrimaryPartCFrame(RightHand.CFrame)
FireSpear.Parent = folder
local weld = Instance.new("Motor6D")
weld.Parent = Handle
weld.Part0 = RightHand
weld.Part1 = Handle
Hitbox:SetNetworkOwner(nil)
local function MakeStuffHappen()
spawn(function()
LookatMouse(Mouse_CFrame,RootPart)
wait(.6)
weld:Destroy()
MoveTowardsMouse(Mouse_CFrame,Hitbox)
end)
end
MakeStuffHappen()
end)
I'm following a tutorial but I don't know how the issue got there.
Your error is pointing to the fact that you are trying to reference fields on an object that doesn't exist. In this case, it's the ´Mouse´ object, which you never supplied from the client.
To fix this, pass the mouse information in when you call the RemoteEvent's FireServer() function.
UIS.InputBegan:Connect(function(input, isTyping)
if isTyping then
return
elseif input.KeyCode == Enum.KeyCode.E and debounce and Character then
debounce = false
local mouseCFrame = Mouse.Hit
FireSpear:FireServer(mouseCFrame)
wait(cd)
debounce = true
end
end)
I made a gun shop website. When I try to buy a gun the first time it works but, when I delete the gun from my inventory and try again it wont work.
Please Help.
local ServerStorage = game:GetService("ServerStorage")
local Vendedor = script.Parent
local ClickDetector = game.Workspace.Lojadearmas.Vendedor.ClickDetector
local Glock = ServerStorage:WaitForChild("G17"):Clone()
ClickDetector.MouseClick:Connect(function(player)
print(player.name)
local Player = player
local Gui = player.PlayerGui.LojaArmas
Gui.Frame.Visible = true
Gui.Frame2.Visible = true
Gui.Glock.Visible = true
Gui.Fechar.Visible = true
Gui.Loja.Visible = true
Gui.Fechar.MouseButton1Click:Connect(function()
Gui.Frame.Visible = false
Gui.Frame2.Visible = false
Gui.Glock.Visible = false
Gui.Fechar.Visible = false
Gui.Loja.Visible = false
print(Player)
end)
Gui.Glock.MouseButton1Click:Connect(function()
if Player.leaderstats.Reais.Value >= 1000 then
Glock.Parent = Player.Backpack
print(Player.leaderstats.Reais.Value)
Player.leaderstats.Reais.Value = Player.leaderstats.Reais.Value - 1000
end
end)
end)
Its because you are cloning it once when you referenced the variable Glock. Try this:
local ServerStorage = game:GetService("ServerStorage")
local Vendedor = script.Parent
local ClickDetector = game.Workspace.Lojadearmas.Vendedor.ClickDetector
local Glock = ServerStorage:WaitForChild("G17")
ClickDetector.MouseClick:Connect(function(player)
print(player.name)
local Player = player
local Gui = player.PlayerGui.LojaArmas
Gui.Frame.Visible = true
Gui.Frame2.Visible = true
Gui.Glock.Visible = true
Gui.Fechar.Visible = true
Gui.Loja.Visible = true
Gui.Fechar.MouseButton1Click:Connect(function()
Gui.Frame.Visible = false
Gui.Frame2.Visible = false
Gui.Glock.Visible = false
Gui.Fechar.Visible = false
Gui.Loja.Visible = false
print(Player)
end)
Gui.Glock.MouseButton1Click:Connect(function()
if Player.leaderstats.Reais.Value >= 1000 then
Glock:Clone().Parent = Player.Backpack
print(Player.leaderstats.Reais.Value)
Player.leaderstats.Reais.Value = Player.leaderstats.Reais.Value - 1000
end
end)
end)
Let me know if you require any further assistance.