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

"22:32:10.109 - Disconnected event because of exception" [NOT SOLVED]?

Asked by 9 years ago

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

3 answers

Log in to vote
2
Answered by
Merely 2122 Moderation Voter Community Moderator
9 years ago

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?

0
I am new-ish at this whole scripting thing, I thought that hit would automatically get the player object, because they HIT the script's parent. SchonATL 15 — 9y
0
You also forgot, there is no "hit", so it would be nil. iaz3 190 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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!

0
That actually didn't work. It went to what it says in the title. But thank you for your time! SchonATL 15 — 9y
0
Huh, then it must have to do with the recent Coding update Roblox did, I have no idea what Roblox is doing now-a-days. :/ Sorry about the inconvenience. ;-; TheeDeathCaster 2368 — 9y
Log in to vote
-2
Answered by 9 years ago

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.

0
Idk. EmeraldSlash 0 — 9y

Answer this question