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

How to make when you pick up the coin it is still there for other players?

i don't really know how to script, so i need help with collectible tokens.

here's collect script:

local db = true
script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db == true then
			db = false
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			script.parent.Transparency = 0
			player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 100
			script.parent.Transparency = 0.7
			script.parent.BackDecal.Transparency = 0.7
			script.parent.FrontDecal.Transparency = 0.7
			wait(3)
			db = true
			script.parent.Transparency = 0
			script.parent.BackDecal.Transparency = 0
			script.parent.FrontDecal.Transparency = 0
		end
	end	
end)

2 comments

0

all you need to do it create the coins locally for the player instead of using server resources

0

i can't understand how

1 answer

✓ Accepted answer

You're doing this on the Server, therefore any changes in that script all players will see. You need to make it so it's on the client side. You can do that via a Local Script and RemoteEvents.

First add a RemoteEvent into ReplicatedStorage. And because you're adding player stats, you'll need to do that server side, so you can add another script and putting it in ServerScriptService and also add another RemoteEvent and call it 'GiveStrengthOnTouch' or anything you want.

Then add this to you Server Script:

script.Parent.Touched:Connect(function(hit)
    local Character = hit.Parent
    local Player = game.Players:GetPlayerFromCharacter(Character)
    if Character:FindFirstChild("Humanoid") ~= nil then
        game.ReplicatedStorage.RemoteEvent:FireClient(Player)
	end 
end)

Local Script:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(player)

local db = true

	if db == true then
          	  db = false

		  -- You will need to change these locations.
          	  script.parent.Transparency = 0
           	 game.ReplicatedStorage.GiveStrengthOnTouch:FireServer()
          	  script.parent.BackDecal.Transparency = 0.7
           	 script.parent.FrontDecal.Transparency = 0.7
          	  wait(3)
          	  db = true
          	  script.parent.Transparency = 0
          	  script.parent.BackDecal.Transparency = 0
          	  script.parent.FrontDecal.Transparency = 0
	end
end)

Then the script to give the player the Strength:

game.ReplicatedStorage.GiveStrengthOnTouch.OnServerEvent:Connect(function(player)
	player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 100
end)

I do apologise if this does not work for you. I hope you get the idea of it anyway.

3 comments

0

wait, where i should put local script?

0

StarterGui or in the Coin. Either one will work

0

Just make sure the variable locations are correct.

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