Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't my script recognize the local player?

Asked by 5 years ago

Ok so to be brief. I am scripting a game where someone is selected to be the leader of a mini game and the leader is given a GUI and in the textbox they can type in a players name and send an air drop to them. The GUI is working fine and the tween event for the airdrop is perfectly fine, but the problem is that when I type in a players name into the textbox and click send, the server doesn't recognize the players name and completely halts the script. Nothing in the "output" is described as being an error so I am just lost. Please help.

game.ReplicatedStorage.sendgun.OnServerEvent:Connect(function()
local val = script.Parent.TextBox.Value.Value   ---- This is where the Players name is being typed
    local text = script.Parent.TextBox
    val = text.Text
    local plr = game.Workspace:FindFirstChild(val) --- Finding the username in game.
    local val2 = script.Parent.dis.Value.Value  -- This is where they type the kind of gun to send.
    local text2 = script.Parent.dis
    val2 = text2.Text
    if plr and plr:FindFirstChild("Humanoid") then  ---- THIS LINE IS THE PROBLEM!!!


---After this the airdrop gets cloned into workspace and sent to the person via a tween event---

0
You are missing arguments on OnServerEvent, fire a player event from local script and do plr.Character on server script Headstackk 45 — 5y
0
So for line 9, I need to do plr.Character:FindFirstChild("Humanoid")? Technozero3 2 — 5y
0
I believe line 9 is okay, because your variable "plr" is not the player but the player's character in Workspace. I'm not good at scripting and don't know what's wrong though Spjureeedd 385 — 5y
0
You should be using the player argument passed by OnServerEvent when it fires, not the player in the Workspace. DeceptiveCaster 3761 — 5y
View all comments (2 more)
0
Where is this script located? And I assume it's a ServerScript but just to be sure, what type of script is it? Spjureeedd 385 — 5y
0
So this is a server script in the GUI frame and fires after the button in the GUI is pushed. Pretty much output says nothing, but its definitely line 9 because I tested other features of it. If I removed line 9 and just had it clone a model into workspace then it works, however, I want the script to clone the object into workspace and via a tween event move to the player's humanoid. Technozero3 2 — 5y

Answer this question