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
5 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.

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

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

01local Popup = script.Parent.Star
02local Debounces = {}
03local part = script.Parent
04local function onTouched(part) 
05   if part.Parent:FindFirstChildOfClass("Humanoid") then
06        local player = game.Players:GetPlayerFromCharacter(part.Parent)
07        if player and not Debounces[player.UserId] then
08            Debounces[player.UserId] = true
09 
10            local Gui = Popup:Clone()
11            Gui.Parent = player:WaitForChild("PlayerGui")
12            Gui:Play()
13            game.ReplicatedStorage.NothingToSeeHere.AddStars:FireClient(player) 
14            wait(2)
15        Gui:Destroy()
View all 26 lines...
0
You just need to destroy it from a localscript Nanomatics 1160 — 5y
0
i'm certain that wouldn't work, the part is in the workspace. 14dark14 167 — 5y
0
It does work OBenjOne 190 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 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:

1game.Workspace.Part.Touched:Connect(function(hit) -- assume the 'Part' is your star
2    local player = Players:GetPlayerFromCharacter(hit.Parent)
3    if player == game.Players.LocalPlayer then
4        game.Workspace.Part:Destroy()
5    end
6end)
0
Nope, the part dissapeared when I stepped on it, but it also dissapeared for other players. 14dark14 167 — 5y
0
try new script retracee 68 — 5y
Ad

Answer this question