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

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

Asked by 4 years ago

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)
0
all you need to do it create the coins locally for the player instead of using server resources jediplocoon 877 — 4y
0
i can't understand how imstealingblindness -11 — 4y

1 answer

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

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.

0
wait, where i should put local script? imstealingblindness -11 — 4y
0
StarterGui or in the Coin. Either one will work xInfinityBear 1777 — 4y
0
Just make sure the variable locations are correct. xInfinityBear 1777 — 4y
Ad

Answer this question