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

Part Click give + 1 coins, not working.. simple script? (Doesn't let me use MouseButton1Click)

Asked by 4 years ago
script.Parent.ClickDetector.MouseClick:Connect(function()
    game.Players.LocalPlayer.leaderstats.Coins.Value = game.Players.LocalPlayer.leaderstats.Coins.Value + 1
    script.Parent:Destroy()
end)

This doesn't work, i had to change from MouseButton1Click to MouseClick because it didn't work, still doesn't work aswell.

0
does it give any errors? looking at this script makes me think that the LocalPlayer value doesnt know where its going to. guywithapoo 81 — 4y
0
its because server scripts cant access the local player Gameplayer365247v2 1055 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

this needs to be the server script:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
game.ReplicatedStorage.event:FireClient(player)--tells the server to which client it should tell info to
game.ReplicatedStorage.event:Connect(function(player)--roblox automaticaly sends who fired the server, because of that the line below will work
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
end)
    script.Parent:Destroy()
end)

local script:

game.ReplicatedStorage.event.OnClientEvent:Connect(function()--recieves that the server sends info, here is means the server wants to know something
game.ReplicatedStorage.event:FireServer()--we fire to the server to give it access to the local player
end)

alternate version since im not sure the scripts above are needed because i dont script with clickdetectors a lot

server script:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
script.Parent:Destroy()
end)
Ad

Answer this question