IntevoidJoin Date: 2016-01-28 Post Count: 132 |
So I'm making a brick that adds a value to a value, and them deletes the brick when clicked.
It's not working, and I can't find out the error, so can somebody take a look at the script?
local replicatedstorage = game:GetService("ReplicatedStorage")
local sticks = replicatedstorage:WaitForChild("Sticks")
function onClicked(playerWhoClicked)
sticks.Value = sticks.Value + 1
wait(0.25)
script.Parent.Parent:Destroy()
end
ClickDetector.MouseClick:connect(OnClicked)
|
|
EgzekielJoin Date: 2011-01-10 Post Count: 1087 |
ClickDetector.MouseClick:connect(OnClicked)
You didn't define ClickDetector.
Also, it's possible the script doesn't work if you use a WaitForChild on an instance that's already present
local sticks
if not replicatedstorage:FindFirstChild("Sticks") then
sticks = replicatedstorage:WaitForChild("Sticks")
end
|
|
IntevoidJoin Date: 2016-01-28 Post Count: 132 |
I defined it, but it still says "OnClicked" is unknown. |
|
IntevoidJoin Date: 2016-01-28 Post Count: 132 |
Bump. |
|
BanTechJoin Date: 2015-12-31 Post Count: 886 |
onClicked not OnClicked |
|
IntevoidJoin Date: 2016-01-28 Post Count: 132 |
Thanks, little errors like that can screw up everything, lol. |
|
IntevoidJoin Date: 2016-01-28 Post Count: 132 |
Script still not working.
Here's what I have:
local replicatedstorage = game:GetService("ReplicatedStorage")
local sticks = replicatedstorage:WaitForChild("Sticks")
local ClickDetector = script.Parent
local sticks
if not replicatedstorage:FindFirstChild("Sticks") then
sticks = replicatedstorage:WaitForChild("Sticks")
end
function onClicked(playerWhoClicked)
sticks.Value = sticks.Value + 1
wait(0.25)
script.Parent.Parent:Destroy()
end
ClickDetector.MouseClick:connect(onClicked)
|
|
BanTechJoin Date: 2015-12-31 Post Count: 886 |
Well first of all you don't need this:
local sticks
if not replicatedstorage:FindFirstChild("Sticks") then
sticks = replicatedstorage:WaitForChild("Sticks")
end
Secondly, is Sticks definitely a child of replicated storage? It may be that near the top, the WaitForChild never gets fulfilled.
If both of those are fine, then check the output. Are there any errors? |
|
IntevoidJoin Date: 2016-01-28 Post Count: 132 |
I'm not getting any errors. |
|
IntevoidJoin Date: 2016-01-28 Post Count: 132 |
Also, here's my hierarchy. |
|
IntevoidJoin Date: 2016-01-28 Post Count: 132 |
https://gyazo.com/0af55aa1f21462e41b7dcbf816f231c9
There you go, sorry. |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
script.Parent.ClickDetector.MouseClick:connect(function(player)
local stats = player:WaitForChild("leaderstats")
local sticks = stats:WaitForChild("Sticks")
sticks.Value = sticks.Value + 1
script.Parent:Destroy()
end) |
|
IntevoidJoin Date: 2016-01-28 Post Count: 132 |
@Time
So would I need this?
ClickDetector.MouseClick:connect(onClicked)
|
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
Nope. Its already in there. |
|
IntevoidJoin Date: 2016-01-28 Post Count: 132 |
This still isn't working.
local replicatedstorage = game:GetService("ReplicatedStorage")
local sticks = replicatedstorage:WaitForChild("Sticks")
local ClickDetector = script.Parent
script.Parent.ClickDetector.MouseClick:connect(function(player)
local stats = player:WaitForChild("leaderstats")
local sticks = stats:WaitForChild("Sticks")
sticks.Value = sticks.Value + 1
script.Parent:Destroy()
end)
Should I get rid of:
local sticks = replicatedstorage:WaitForChild("Sticks") |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
--Is sticks a Value inside of ReplicatedStorage? If it is then just do this.
--I thought you were trying to change a players stats.
local sticks = game.ReplicatedStorage:WaitForChild("Sticks")
script.Parent.ClickDetector.MouseClick:connect(function(player)
sticks.Value = sticks.Value + 1
script.Parent:Destroy()
end) |
|
IntevoidJoin Date: 2016-01-28 Post Count: 132 |
This still isn't working. |
|
IntevoidJoin Date: 2016-01-28 Post Count: 132 |
Also, it is not giving me any errors. |
|
ez_streetJoin Date: 2013-07-11 Post Count: 364 |
The reason its not working is because its a localscript, it needs to be a normal script. |
|
IntevoidJoin Date: 2016-01-28 Post Count: 132 |
@iMung
I changed it, but it still didn't change anything. |
|
usermvpJoin Date: 2013-06-29 Post Count: 188 |
Is there a VALUE in the item "Sticks" that's name is "Value" or is Sticks an IntValue?
Insert this into a REGULAR script, then insert the script into a part that you want the Players to click for it to happen. Make sure there IS a ClickDetector in the item.
local rs = game:GetService("ReplicatedStorage")
local sticks = rs:FindFirstChild("Sticks")
print("Variables loaded")
script.Parent.ClickDetector.MouseClick:connect(function()
script.Disabled = true
sticks.Value = sticks.Value + 1
wait(0.25)
script.Parent:remove()
script.Disalbed = false
end)
Unless you want it to be a leaderstat value, then I can script that.
|
|