When i touch a part, its meant to disappear and add +1 to the leaderstats
your using :waitForChild, its incorrectly spelled, Try :WaitForChild instead.
I just realized, Your using a localscript, Localscripts only affect the players screen, And not the literal values that the server sees. Try using a script in serverscript service instead.
Oh and your using two colons.
Paste this into a Server Script.
local Players = game:GetService("Players")
local Coin = workspace.Coin
Players.PlayerAdded:Connect(function(Player)
local Stats = Instance.new("Folder", Player)
Stats.Name = "leaderstats"
local Coins = Instance.new("NumberValue", Stats)
Coins.Name = "Coins"
Coins.Value = 0
end)
Coin.Touched:Connect(function(Hit)
if (Hit.Parent:FindFirstChild("Humanoid")) and (Players:FindFirstChild(Hit.Parent.Name)) and (Coin.CanTouch.Value == true) then --// Checks if the part that hit the coin is a part of a Player Character and if the CanTouch value is true.
local Player = Players:GetPlayerFromCharacter(Hit.Parent)
Player.leaderstats.Coins.Value += 1
Coin.Transparency = 1
Coin.CanTouch.Value = false
task.wait(3)
Coin.Transparency = 0
Coin.CanTouch.Value = true
end
end)
Your trying to turn a MODEL transparent, Maybe use a for loop to get all the children of that model THEN make it transparent
Make a part In the model that covers the whole coin.
local Hitbox = Coin.Hitbox --Change Hitbox to the part you named it to.
Hitbox.Touched:Connect(function(hit)
if (hit.Parent:FindFirstChild("Humanoid")) and (Players:FindFirstChild(hit.Parent.Name)) and (Coin.CanTouch.Value == true) then
local plr = Players:GetPlayerFromCharacter(hit.Parent)
local Value = plr:WaitForChild("leaderstats").Coins
Value.Value += 1
for i, v in pairs(game.Workspace.Coin:GetChildren()) do
v.CanTouch = false
v.Transparency = 1
end
task.wait(3)
for i, v in pairs(game.Workspace.Coin:GetChildren()) do
v.CanTouch = true
v.Transparency = 0
end
end
end)
Oh, Your using game.Players.LocalPlayer, You shouldn’t use that It only works on localscripts and will definetly lead to an error. instead put “player” in the function parenthesis like this
Something That one specific player can trigger:Connect(function(player)
player.Character:Destroy()
end)
Besides, Its not like your going to use a player anything outside of doing something to the player whenever it triggers something.
The problem you had here is disabling the script, once you ran script.Disabled = true
it wont do anything at all, unless other script enables it.
This is true, you shouldn’t disable scripts from within the script itself because the function wont continue or return and it can then only be re-enabled externally, so if you are enabling it externally you should disable it externally.