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)
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)
"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)