This wasn't very specific, so I didn't know what to look for to fix. It's for a Halloween game I'm making, coming 2015 btw. Here's the script:
script.Parent.Touched:connect(function(touchedEffect) local localplayer = hit.Parent wait(0.1) script.Parent.Transparency = 1 script.Parent.CanCollide = false script.Parent.Script.Disabled = true localPlayer.leaderstats.Pumpkins.Value = Player.leaderstats.Pumpkins.Value +1 wait(10) script.Parent.Transparency = 0 script.Parent.CanCollide = true script.Parent.Script.Disabled = false end)
And yes, I do have a leaderstats script. Anybody know what could be wrong?
~~EDIT~~ Okay, okay, I came up with this script for test solo, but no player is going to be called Player1. How would I get the actual players in the game? Oh, and here's the script (might be helpful):
wait(1) local character = game.Workspace.Player1 local player = game.Players:GetPlayerFromCharacter(character) if player then script.Parent.Touched:connect(function(touchedEffect) wait(0.1) script.Parent.Transparency = 1 script.Parent.CanCollide = false script.Parent.Script.Disabled = true player.leaderstats.Pumpkins.Value = player.leaderstats.Pumpkins.Value +1 wait(10) script.Parent.Transparency = 0 script.Parent.CanCollide = true script.Parent.Script.Disabled = false end) end
First problem I see:
local localplayer = hit.Parent
That's definitely not going to be a player object, it's probably going to be a character. A character doesn't have a leaderstats object to go with it. Given a part, you can check if the part's parent is a character of a player using Players:GetPlayerFromCharacter(model).
Also, hit is not defined. What is hit? And where is Player defined?
Hmm, I see a few errors, lets try rewritting the code [Keep in mind, this code has been untested, but should work];
local Debounce = true --Heres our Debounce, Debounce is used to keep the code from firing multiple times local function Pumpkin(hit) --Here is our function [The local is optional, I just like to use it] if hit.Parent and #hit.Parent:GetChildren() > 0 and game.Players:GetPlayerFromCharacter(hit.Parent) and Debounce then --This will check to see if hit.Parent is existant, has objects within it [Lol how doesn't it?], checks to see if the object that touched it is a Player, and does a debounce so that it doesn't fire multiple times Debounce = false --Heres our Debounce, this'll keep the code from firing multiple times local Player = game.Players:GetPlayerFromCharacter(hit.Parent) --This will get the Player from the Player's Character if Player and Player:FindFirstChild("leaderstats") and Player.leaderstats:FindFirstChild("Pumpkins") then --This will check to see if 'leaderstats, and 'Pumpkins' exist within the Player Player.leaderstats.Pumpkins = Player.leaderstats.Pumpkins + 1 --This will increase Pumpkins by 1 script.Parent.Transparency = 1 --This will make the script's Parent's Transparent [If is a Part-Type object] script.Parent.CanCollide = false --This will make the script's Parent Throughable [If is a Part-Type object] wait(10) script.Parent.Transparency = 0 --This will make the script's Parent non-Transparent again script.Parent.CanCollide = true --This will make the script's Parent non-Throughable again Debounce = true --This will enable the Player to use it again end --This ends the code for the 'if' statement that checks to see if 'leaderstats' and 'Pumpkins' exist end --This ends the code for the 'if' statement that checks to see if 'hit.Parent' exists, there are objects within it, checks to see if 'hit.Parent' is a Player, and checks to see if 'Debounce' is enabled so that it can fire end --This ends the code for the function script.Parent.Touched:connect(Pumpkin) --Now whenever the Part is touched, it'll fire an event [The 'Touched' event] that which will fire the function
Hope this helped!
How about doing
local player = hit.Parent.leaderstats
or
game.Players.LocalPlayer.Character
I don't see much in the script that could go wrong except the leaderstats part.