Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Make a part destroy localy? ( Advance ) !

When a player steps on a part it gets destroyed only for him, but not for others.

Example (not important) - In my game, you can collect stars as a currency basically, but so far when you collect the star it gives you 1 point and the star remains there making people confused if they really touched the part.

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid ~= nil then
		script.Parent:Destroy() -- making this local
	end
end)

Here is the full script I made ( you can edit this if you want, It will take more time tho). [ script inside a part ]

local Popup = script.Parent.Star
local Debounces = {}
local part = script.Parent
local function onTouched(part)	
   if part.Parent:FindFirstChildOfClass("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(part.Parent)
        if player and not Debounces[player.UserId] then
            Debounces[player.UserId] = true

            local Gui = Popup:Clone()
            Gui.Parent = player:WaitForChild("PlayerGui")
            Gui:Play()
	        game.ReplicatedStorage.NothingToSeeHere.AddStars:FireClient(player)  
			wait(2)
		Gui:Destroy()
	    --Debounces[player.UserId] = false      ( inactive )
        end
    end
end

part.Touched:Connect(onTouched)
local Star = script.Parent
while true do
	Star.CFrame = Star.CFrame * CFrame.fromEulerAnglesXYZ(0.1, 0, 0)
	wait()
end

3 comments

0

You just need to destroy it from a localscript

0

i'm certain that wouldn't work, the part is in the workspace.

0

It does work

1 answer

You are confusing yourself with this one, Its okay, I did too when I had a problem like this. To remove a part locally you will just use one localscript in your starterplayer. Remote Events only function when you want to locally send a message to the server, not a server event to client. You will need to use a localscript along the lines of this:

game.Workspace.Part.Touched:Connect(function(hit) -- assume the 'Part' is your star
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if player == game.Players.LocalPlayer then
		game.Workspace.Part:Destroy()
	end
end)

2 comments

0

Nope, the part dissapeared when I stepped on it, but it also dissapeared for other players.

0

try new script

This discussion is preserved as it was. New answers, comments, and votes are closed.