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

Make a part destroy localy? ( Advance ) !

Asked by
14dark14 167
4 years ago

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
0
You just need to destroy it from a localscript Nanomatics 1160 — 4y
0
i'm certain that wouldn't work, the part is in the workspace. 14dark14 167 — 4y
0
It does work OBenjOne 190 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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)
0
Nope, the part dissapeared when I stepped on it, but it also dissapeared for other players. 14dark14 167 — 4y
0
try new script retracee 68 — 4y
Ad

Answer this question