I’m having an issue with calling events.
I have these lines of code.
local playername = humanoid.Parent.Name
script.GUIStart:FireClient(playername)
It says, unable to cast to object. Please help, I am not very experienced in casting events.
If this has already been asked and solved, please direct me to the thread.
Thank you!
Slight thing with solution, I did not know FireAllClients and FireClient were different, so techincally post #2 is the solution, while I learned of my issue in post 16/17. Credit should go to both of these guys.
local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
local playername = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent).Name
script.GUIStart:FireClient(player,playername)
You need to fire the player argument not the name (not sure if u want to send it or use it as a player arg) If you don’t want to send the player name, just remove the playername variable from the firing function and the variable itself.
This fixes the issue, but then this happens. This is a GUI script.
game.Workspace.CORE.CORE.Script.GUIStart.OnClientEvent:Connect(function(player,playername)
print("caught")
print(script.Parent.Parent.Parent.Name)
print(player.name)
if script.Parent.Parent.Parent.Name == player.name then
script.Parent.Enabled = true
end
end)
Where is says print player.name, it comes up as nil. Why is this?
This is the portion of the server script used.
core.Touched:Connect(function(hit)
print("burning")
if hit.Name == "Handle" then
humanoid = hit.Parent.Parent.Humanoid
else
humanoid = hit.Parent.Humanoid
end
print ("skin detcted")
humanoid.Health = 0
local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
local playername = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent).Name
script.GUIStart:FireClient(player,playername)
end)
core.Touched:Connect(function(hit)
print("burning")
if hit.Name == "Handle" then
humanoid = hit.Parent.Parent.Humanoid
else
humanoid = hit.Parent.Humanoid
end
print ("skin detcted")
humanoid.Health = 0
local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
print(player.Name)
script.GUIStart:FireClient(player)
end)
game.Workspace.CORE.CORE.Script.GUIStart.OnClientEvent:Connect(function(player)
print("caught")
print(script.Parent.Parent.Parent.Name)
print(player.Name)
print(player)
if script.Parent.Parent.Parent.Name == player.Name then
script.Parent.Enabled = true
end
end)
Try those, lets see what is it about… Does it print the player’s name in the Server? And does it print in the Client?
No need to pass the player name as a seperate variable
core.Touched:Connect(function(hit)
print("burning")
if hit.Name == "Handle" then
humanoid = hit.Parent.Parent.Humanoid
else
humanoid = hit.Parent.Humanoid
end
print ("skin detcted")
humanoid.Health = 0
local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
script.GUIStart:FireClient(player)
end)
game.Workspace.CORE.CORE.Script.GUIStart.OnClientEvent:Connect(function()
local player = game.Players.LocalPlayer
print("caught")
print(script.Parent.Parent.Parent.Name)
print(player.name)
if script.Parent.Parent.Parent.Name == player.name then
script.Parent.Enabled = true
end
end)
Oh well true, didn’t take a closer look. I tried the script with my own version, worked… (mine version)
Seems like an other issue… OP may we see the upper part of the code?
Test the code that has been provided instead of dismissing it. You are having issues with the remote events, and I have experience using remote events. I reckon that I probably know what would work and what wouldn’t
Wait, when a client event is fired, do all local scripts capture it? This GUI is inside the player, so would all those GUI scripts capture it? Or only the one being fired to the player?