script.Parent.MouseButton1Click:connect(function(lool) local name = script.Parent.Parent.Name.Text for i,v in pairs(game.Players:GetChildren()) do if v.Name == name then for i,z in pairs(game.Workspace.Zombies:GetChildren()) do if z.Owner.Value == script.Parent.Parent.Parent.Parent.Parent.Parent.Name then z:MoveTo(v.Torso) end end end end end)
This script is basically supposed to get a zombie to attack the player that has their name written in a box. It doesn't work. No errors or anything. Help please?
From my knowledge, normal scripts will not work inside PlayerGui. If you want a player to have control via GUI over something all players see (a server-side thing like your zombies) you'll have to use Remote Events and a Local Script. I'll give you my rendition of this, but promise me you'll learn from it.
This will be a normal script located in ServerScriptService (You can put it anywhere not related to a player, but I would put it in there):
local ZAttack = Instance.new("RemoteEvent", game.ReplicatedStorage) ZAttack.Name = "ZAttack" ZAttack.OnServerEvent:connect(function(player,name) --'player' is the client that calls the function, 'name' is what that player inputs into the function's argument(or was it called parameter? idk I don't have formal training.) local target = game.Players:FindFirstChild(name) if target == nil then return end --Switched out the check if the target exists for i,z in pairs(game.Workspace.Zombies:GetChildren()) do if z.Owner.Value ~= player.Name then --Your original check would've left you vulnerable too! z:MoveTo(target.Character.Torso) --Players don't have torsos but their characters do! end end end)
And put this in a Local Script that will replace your current one:
script.Parent.MouseButton1Click:connect(function() game.ReplicatedStorage.ZAttack:FireServer(script.Parent.Parent.Name.Text) --That's the Argument/Parameter in the parenthesis that I mentioned before! end)
tl;dr I did it for you, dissect my script(s) so you can do it too!