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

How can I change a property of a part for the localplayer?

Asked by 1 year ago

I have made a code when you touch a block the properties of an other part changes. It works, but everyone sees it. I want that the property only changes for the local player. Can someone help me? these are the codes I have made 2 local scripts in the startergui.

local Workspace = game.Workspace

local mainpart = Workspace.Touchablewall1
local secondarypart = Workspace.Part28
local thirdpart = Workspace.Part29
local secondmainpart = Workspace.Touchablewall2
local Players = game:GetService("Players")

local db = true
mainpart.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if db == true then
            db = false
            secondarypart.Transparency = 1
            secondarypart.CanCollide = false
            mainpart.Transparency = 0
            thirdpart.CanCollide = true
            thirdpart.Transparency = 0
            secondmainpart.Transparency = 1
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
            mainpart.Transparency = 0
            secondarypart.Transparency = 1
            secondarypart.CanCollide = false
            thirdpart.CanCollide = true 
            thirdpart.Transparency = 0
            secondmainpart.Transparency = 1
            wait(0.1)
            db = true
            mainpart.Transparency = 1
            secondarypart.Transparency = 0
            secondarypart.CanCollide = true
            thirdpart.CanCollide = false
            thirdpart.Transparency = 1
            secondmainpart.Transparency = 0
        end
    end 
end)

-----other script


local Workspace = game.Workspace local mainpart = Workspace.Touchablewall2 local secondarypart = Workspace.Part29 local thirdpart = Workspace.Part28 local secondmainpart = Workspace.Touchablewall1 local db = true mainpart.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then if db == true then db = false secondarypart.Transparency = 1 secondarypart.CanCollide = false mainpart.Transparency = 0 thirdpart.CanCollide = true thirdpart.Transparency = 0 secondmainpart.Transparency = 1 local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1 mainpart.Transparency = 0 secondarypart.Transparency = 1 secondarypart.CanCollide = false thirdpart.CanCollide = true thirdpart.Transparency = 0 secondmainpart.Transparency = 1 wait(0.1) db = true mainpart.Transparency = 1 secondarypart.Transparency = 0 secondarypart.CanCollide = true thirdpart.CanCollide = false thirdpart.Transparency = 1 secondmainpart.Transparency = 0 end end end)

0
Just a suggestion, you don't have to define ``local Workspace = game.Workspace`` as ``workspace`` is already a built-in variable that acts as the workspace. boredlake 256 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

Just make that scripts local and put them into starter player scripts. Message me if it would work or not! If it wont work you should use an remote event with fire client.

0
I made both script local scripts and I put them in starter player scripts but it didn't work. Can you help me with the script? I don't know how to use remote events and fire client. MuhammadHH11 2 — 1y
0
Make an script (in part or server script storage), add variable with your remote event in rep storage, then when its get touched, use remote:FireClient. Then make your local script function activate on remote event with onClientEvent. This may help you. SashaPro336 47 — 1y
0
Also i dont recommend you to change leaderstats using local script, because you cant save it in the future and other. SashaPro336 47 — 1y
0
Thank you! MuhammadHH11 2 — 1y
0
:D SashaPro336 47 — 1y
Ad

Answer this question