Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Remote event dosent fire?

I am trying to make a script that once you click on specific part it would add a value inside local player 1 script

script.Parent.ClickDetector.MouseClick:Connect(function(hit)
	local character = hit.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	
	game.ReplicatedStorage.GiveIng1:FireClient(player)
end)

2 script

game.ReplicatedStorage.GiveIng1.OnClientEvent:Connect(function()
	local player = game.Players.LocalPlayer
	player.Item.Value = 1
	player.InvSpace = true
end)

2 answers

✓ Accepted answer

Well, MouseClick function indexes the player's instance and not the character's. Touched event returns the player's character. To simply fix your issue, In your script 1:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    game.ReplicatedStorage.GiveIng1:FireClient(player)
end)

Lemme know if it helps!

not totally sure since i never tried not defining rs but you may want to get the ReplicatedStorage service as a variable, then use that variable e.g.

rs = game:GetService("ReplicatedStorage")


script.Parent.ClickDetector.MouseClick:Connect(function(hit)
    local character = hit.Parent
    local player = game.Players:GetPlayerFromCharacter(character)

    game.rs.GiveIng1:FireClient(player)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.