This is probably a very simple issue, but i cant find anyway to fix it. I have tried searching the devforum and fixing it myself but had no luck.
So basically the script is within a part, so i should be able to do something such as:
script.Parent.Touched:Connect(function()
But i can’t. Im not too sure what the issue is. It could be because its being called from within a function but not 100% sure.
Here is the script:
local repStore = game.ReplicatedStorage
local events = repStore.Core.Events
local function addAtmosphere(hit)
if hit.Parent:FindFirstChild("Humanoid") then -- Issue occurs here saying: attempt to index nil with 'Parent'
return
end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
events.AtmosphereAdd:FireClient()
end
script.Parent.Touched:Connect(function()
addAtmosphere()
end)
The script is inside the part and is a server script.
oh yeah to fire to a client u must specify the player u are firing to. If you wish to fire to all clients use :FireAllClients, otherwise do :FireClient(plr)
Hello, the problem is that you’re not firing the event to a Player and you’re returning the function when actually it finds a Humanoid. This should fix it:
local Players = game:GetService("Players")
local repStore = game:GetService("ReplicatedStorage")
local events = repStore.Core.Events
local function addAtmosphere(hit)
if hit then
if hit.Parent:FindFirstChild("Humanoid") then -- Issue occurs here saying: attempt to index nil with 'Parent'
local player = Players:GetPlayerFromCharacter(hit.Parent)
events.AtmosphereAdd:FireClient(player)
end
end
end
script.Parent.Touched:Connect(addAtmosphere)
This has fixed the problem and currently i am not getting any errors, but the client script (local script) doesnt seem to be receiving the event when its fired. I tried adding a print event and the text was in the output.
Is this something to do with the local script or the server side?
local repStore = game:GetService("ReplicatedStorage") // getting the RS service
local events = repStore.Core.Events
local function addAtmosphere(hit)
if not (hit and (hit.Parent) and (hit:FindFirstChild("Humanoid"))) then
return
end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
events.AtmosphereAdd:FireClient(player, "DABABY LESS GOOO")
end
script.Parent.Touched:Connect(addAtmosphere)