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

Orb decides to not sell itself and instead just float around?

Asked by 2 years ago

So what I'm trying to do is have a part called "Seller" make the orbs sell when they touch them, but instead the orb just sits around and does nothing when touching the seller. How would I fix this script?

local player = game.Players.LocalPlayer
local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash") 
local multiplier = 1
local orbvalue = 5
script.Parent.Touched:Connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChildWhichIsA("Seller") then
        cash.Value += orbvalue * multiplier
        script.Parent:Destroy()
        print("hit")
    end
end)
0
idk I had something like that happen once. I also used a "this and this and this" statement and it's just too glitchy. You can either make different if statements inside each other or just cut out "hit and hit.Parent" cause they are useless in this case. btw idk if destroying the script and THEN printing will work HeroFigo 81 — 2y

2 answers

Log in to vote
1
Answered by 2 years ago

The “seller” your trying to find doesn’t exist in the character model. The seller part is found in workspace, not in the character. Do everything T3_MasterGamer gave you except modify a part of the script:

-- Modified script (Also a normal script)

local multiplier = 1
local orbvalue = 5
script.Parent.Touched:Connect(function(hit)
    if hit and hit.Parent and game.Workspace:FindFirstChild(“Seller”, true) and game.Players:GetPlayerFromCharacter(hit.Parent) then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash") 

        cash.Value += orbvalue * multiplier
        print("hit")
        script.Parent:Destroy()
    end
end)
Ad
Log in to vote
0
Answered by 2 years ago

"Seller" isn't a class object. Instead, use Instance:FindFirstChild().

Also, I've observed you used Players.LocalPlayer, so that means you are using a LocalScript. Remember, LocalScripts won't work in the workspace. Use a normal script instead, and if you want to send anything to the client and not the server, use RemoteEvents.

NOTE: PRINTING ANYTHING AFTER DESTROYING THE PART WON'T WORK, SINCE THE PART, THE SCRIPT, AND ITS DESCENDANTS PARENTS ARE SET TO NIL, ITS PROPERTIES ARE LOCKED, DISABLED, AND ALSO SET ITSELF TO NIL.

-- Normal Script inside the orb

local multiplier = 1
local orbvalue = 5
script.Parent.Touched:Connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Seller") and game.Players:GetPlayerFromCharacter(hit.Parent) then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash") 

        cash.Value += orbvalue * multiplier
        print("hit")
        script.Parent:Destroy()
    end
end)
0
this is still not working, it just rolls on it again. MrBucketOfficial 39 — 2y

Answer this question