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

Remote event dosent fire?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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!

Ad
Log in to vote
0
Answered by 4 years ago

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)

Answer this question