I have made a script which when you put an "Empty Cup" on a part it turns into "Coke". This is great however I have scripted it so it only works for me and that's bad here is the script:
function tch(h) if (h.Parent.Name == "Empty Cup") then h.Parent.Name = "Coke" script.Parent.Parent.Spill.Transparency = 0.1 wait(0.3) game.Workspace.dinoroar1.Coke.Handle.Full.Transparency = 0 wait(0.2) script.Parent.Parent.Spill.Transparency = 1 end end script.Parent.Touched:connect(tch)
I really need it to work for anyone who touches it with an Empty Cup someone please help!
Assuming this is a localscript, put in this code:
local character = game:GetService("Players").LocalPlayer.Character -- i used local player for identifying the player function tch(h) if (h.Parent.Name == "Empty Cup") then h.Parent.Name = "Coke" script.Parent.Parent.Spill.Transparency = 0.1 wait(0.3) character.Coke.Handle.Full.Transparency = 0 wait(0.2) script.Parent.Parent.Spill.Transparency = 1 end end script.Parent.Touched:connect(tch)
if it is a serverscript, check out devrbxpage/GetPlayerFromCharacter for details!
LocalPlayer is used in codes. when used it refers to you as a player. It's the equivalent of game.Players.Your_name
but it can only be accessed through local scripts. This is useful when you want to create individual changes without creating a system that takes the players username into consideration.
On line 6 you use your own character name but what you could use to make it available to everyone is to type game.Players.LocalPlayer.Character.Coke.Handle.Full.Transparency = 0
.
Hopefully, this should work if you put it in a local script.
local player = game.Players.LocalPlayer local Character = player.Character or player.CharacterAdded:Wait() function tch(h) if (h.Parent.Name == "Empty Cup") then h.Parent.Name = "Coke" script.Parent.Parent.Spill.Transparency = 0.1 wait(0.3) Character.Coke.Handle.Full.Transparency = 0 wait(0.2) script.Parent.Parent.Spill.Transparency = 1 end end script.Parent.Touched:connect(tch)