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

Why does my coin pick up script give me 0 cash instead of 100?

Asked by 5 years ago

So basically this script is supposed to be so when you collect a coin, it gives you a certain amount of coins then removes itself. I am trying to make it so if they have a certain upgrade they get more money from the coins but when I collect it, it gives me no cash even though I set my multiplier to 10.

local baseamount = 10
script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if hit.Parent:FindFirstChild("Humanoid") then
        local multvalue = player.extra.multiplier.Value
        local multipler = baseamount * multvalue
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + multipler
        script.Parent:Destroy()

    end
end)
0
Try printing out what "multipler" is before destroying the script, see if it has a value. Is this a local script? DinozCreates 1070 — 5y
0
Based on your script if multiplier has no value then 10 x anything is nothing, so it wouldnt work. DinozCreates 1070 — 5y
0
The multiplier has a value of 10. I set it while in studio. It's not a local script aswell. If I set it using a script when I join it works. How would I make it so that when it changes it will always work? TypicallyPacific 61 — 5y
0
Thats your issue. Changing the value while in studio counts as a client sided change, and will not be recognized by a server script. DinozCreates 1070 — 5y
View all comments (2 more)
0
I also recommend you follow the changes Diezel outlined in his answer, they're all good. Trying changing the players multiplier value inside the script, and it should work correctly.(just for testing) DinozCreates 1070 — 5y
0
In case i wasnt clear, this is a Filtering Enabled issue, changes made to server created values from the client will not replicate. If the server created the Multiplier then the server MUST change the value. DinozCreates 1070 — 5y

1 answer

Log in to vote
0
Answered by
Trew86 175
5 years ago
Edited 5 years ago

Try this:

local baseamount = 10
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local extraPoints = player:FindFirstChild("extra")
if extraPoints ~= nil then 
local multvalue = extraPoints.multiplier.Value
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + multvalue*baseamount
else
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + baseamount
end
script.Parent:Destroy()
end
end)

I changed some things:

  1. I think the script should check for the humanoid before getting the player from the character.

  2. I made the script respond to both scenarios: If there is an "extra" and if there isn't. If there is, give the player the score times the player's multiplier value. If there's no extra, just give the baseamount.

  3. I put script.Parent:Destroy() outside the "if extra ~= nil" expression. Since it should happen no matter what the scenario.

0
It works, but when I change the value it doesn't update and it keeps giving me the multiplier I had when I joined. TypicallyPacific 61 — 5y
0
oops, I meant "extraPoints" at line 6, not "extra". Editing it.. Trew86 175 — 5y
0
It still doesn't update when I pick up the coin. TypicallyPacific 61 — 5y
0
same with line 7, my bad! Trew86 175 — 5y
View all comments (2 more)
0
I just realized, if you edit it manually it doesn't work. It needs to be updated by the server, TypicallyPacific 61 — 5y
0
You just realized? I commented that on your question a while ago. DinozCreates 1070 — 5y
Ad

Answer this question