Greetings, I’v been trying to improve my admin gui with a textbox where i could enter a players username and then do random activities with it. However, iv come with a problem (possibly multiple problems) trying to send data (the name of the user) from the client to the server and I cant figure out how.
Local Script
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.user.Text == "" then --this checks if the textbox is blank, if it does then this would make the event choose a random player in the server
game.ReplicatedStorage.events.grenade:FireServer(script.Parent.Parent.user.Text, true) --this is done by puting "true" instead of "false"
else
game.ReplicatedStorage.events.grenade:FireServer(script.Parent.Parent.user.Text, false)
end
end)
Server Script
game.ReplicatedStorage.events.grenade.OnServerEvent:Connect(function(name, space)
wait(math.random(2,5))
local Players = game:GetService("Players")
local PlayerList = Players:GetPlayers()
if space == true then
local Chosen1 = math.random(1, #PlayerList)
local Player1 = PlayerList[Chosen1]
local Character1 = Player1.Character
local boom = Instance.new("Explosion", workspace)
boom.Position = Character1.HumanoidRootPart.Position
print("chosen random")
else
local Playercheck = Players:FindFirstChild(name)
if Playercheck then
local Chosen1 = name
local Player1 = PlayerList[Chosen1]
local Character1 = Player1.Character
local boom = Instance.new("Explosion", workspace)
boom.Position = Character1.HumanoidRootPart.Position
print("player chosen")
else
print("no players found, perhaps error. sending back remotefunction (will script later)")
end
end
end)
It always outputs the last print, even if the TextBox is blank or when I type my username. Can anyone help?
If anyone needs clarification, ask me.