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

This script works in Play Solo and Run, but not in an actual game, how can I fix this?

Asked by
jm34 7
8 years ago
01function onTouch(hit)
02if hit.Name == "MoneyBrick" then
03game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value + 1
04 
05hit:Destroy()
06 
07 
08 
09end
10end
11 
12script.Parent.Touched:connect(onTouch)

This script makes it so when a "MoneyBrick" goes over the block the script is in it deletes it and then give you 1 money.

1 answer

Log in to vote
0
Answered by
thePyxi 179
8 years ago

Having a 'LocalPlayer' inside a server script will not work among in-game play. The script below is a modified version, which checks to see the player for touching the brick and checks the name. The script below is supposed to be put into the brick and in a server script, not a local script.

01function onTouch(hit) --Start the function
02 
03    local check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button
04 
05    if check ~= nil and script.Parent.Name == "MoneyBrick" then --If a human is found and the name of the brick is "MoneyBrick" , then
06 
07        local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human
08        local stats = user:FindFirstChild("leaderstats") --Find moneyholder
09 
10        if stats ~= nil then --If moneyholder exists then
11 
12            local money = stats:FindFirstChild("Money") --Get money
13 
14            money.Value  = money.Value +1 --amount of money added to the value
15 
View all 23 lines...
0
So I replaced this script with the old one and in Output it just said "Not named correctly." repeatedly even though the bricks are called MoneyBrick jm34 7 — 8y
0
what do I do jm34 7 — 8y
0
Can you send a screenshot link of what you are specifically trying to do? thePyxi 179 — 8y
0
Ok I made a picture explaining the problem: https://drive.google.com/file/d/0B5Sa_dRUhnR9ZV9JeFBqaG15alU/view?usp=sharing jm34 7 — 8y
Ad

Answer this question