##Answer:
Step-By-Step explanation
(This is just to add a bit more of a description as to why it didn't actually fire.)
##Problem:
- The reason it didn't work was because, player variable wasn't defined in your script.
- Another reason was, you're trying to
:FireClient to an instance that is null, THERE'S no plr parameter on your script, which again leads to another error.
##Solution:
Make sure you've defined the player, also try to avoid using many if statement's in your code that are not needed, as it makes it harder to debug.
##Reccomendation:
Use GetPlayerFromCharacter() as DovyDas stated, because it gets the player who has made a contact with a 3D dimensional object, and is generally easier than using if-statements as the function returns a player hence the name "GetPlayerFromCharacter"
##Fixed Script:
(You can use anyone of these scripts stated, as they both act and do the same thing.)
1st script:
local repstorage = game.ReplicatedStorage
local event = repstorage:WaitForChild("StartTimer")
local player = game:GetService("Players").PlayerAdded:Connect(function(plr)
local Part = game.Workspace.Part
Part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
event:FireClient(plr)
print("fired")
end
end)
end)
2nd script:
local player = game:GetService("Players").PlayerAdded:Connect(function(p)
local repstorage = game.ReplicatedStorage
local event = repstorage:WaitForChild("RemoteEvent")
local part = game.Workspace.Part
part.Touched:Connect(function(hit)
local plr = nil
if hit.Parent:IsA("Model") then
plr = hit.Parent
end
if hit.Parent.Parent:IsA("Model") then
plr = hit.Parent.Parent
end
if plr then
else
return
end
if game.Players:FindFirstChild(plr.Name) then
print (7)
plr = game.Players:FindFirstChild(plr.Name)
end
event:FireClient(p)
print("fired")
end)
end)
P.S: This was kind of rushed, so sorry for bad grammar!
####Thanks, JesseSong!
If you need any further help, don't hesitate to comment, or leave me a DM!
2 comments
Is this a regular script or a localscript?
server script